<template>
<van-list v-model="loading" :immediate-check="false" class="nowPlayingList-wrap" :finished="finished" finished-text="没有更多了" @load="onLoad">
  <section data-page=".movie" class="movie singleton page active" :style="'height:'+heighta+'px'+';'">
    <div class="page-wrap classic active">
      <div class="tab-block">
        <div class="tab-content">
        <!-- <van-cell > -->
          <div  class="page classic" data-hot=".classic">
            <div class="list-wrap" style="margin-top: 0px">
              <div class="classic-movies">
                <div class="classic-movies-list">
                  <a v-for="i in filmitems" :key="i.filmId" href="javascript:;">
                    <div class="classic-movie">
                      <div class="avatar">
                        <img
                          :src="i.poster"
                          onerror="this.style.visibility='hidden'"
                        />
                      </div>
                      <div class="movie-info">
                        <div class="title line-ellipsis">{{i.name}}</div>
                        <div class="english-title line-ellipsis">
                          {{i.director | directorfilter}}
                        </div>
                        <div class="actors line-ellipsis">{{i.category}}</div>
                        <div class="show-info line-ellipsis">
                          {{i.premiereAt | premiereAtfilter}}{{i.nation}}上映
                        </div>
                      </div>
                      <div class="movie-score">
                        <div class="score line-ellipsis">
                          <span :class="i.grade? 'grade' :'no-score'"> {{i.grade | gradefilter}}分</span>
                        </div>
                      </div>
                    </div>
                  </a>
                </div>
              </div>
            </div>
          </div>
        <!-- </van-cell> -->
        </div>
      </div>
    </div>
  </section>
</van-list>
</template>
<style scoped>
.no-score {
    width: 60px;
    height: 17px;
    font-size: 12px;
    color: #999;
    line-height: 17px;
    display: inline-block;
    text-align: center;
}
.page.singleton,
.page.singleton-notab {
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}
.page.singleton {
  -webkit-transform: none !important;
  transform: none !important;
}
.page.active {
  display: block;
}
.page.singleton-notab .page-wrap,
.page.singleton .page-wrap {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: auto;
}
.page-wrap .page {
  display: block;
}
.page {
  position: absolute;
  width: 100%;
  display: none;
}
.classic .list-wrap,
.f-hot .list-wrap,
.n-hot .list-wrap {
  background-color: #f5f5f5;
}
.more {
  line-height: 40px;
  height: 40px;
  text-align: center;
}
.classic-movies {
  background-color: #fff;
  padding-top: 14.5px;
}
.classic-movies a {
  text-decoration: none;
  display: block;
  color: #666;
}
.classic-movie {
  position: relative;
  margin: 0 0 20px 20px;
  display: -webkit-box;
  display: flex;
  -webkit-box-align: start;
  align-items: flex-start;
}
.classic-movie .avatar {
  display: inline-block;
}
.classic-movie .avatar img {
  width: 66px;
  height: 94px;
}
.page.singleton-notab .page-wrap,
.page.singleton .page-wrap {
  position: absolute;
  width: 100%;
  height: 100%;
  overflow: auto;
}
.page-wrap.active {
  display: block;
}
.page-wrap {
  display: none;
  background-color: #fff;
}
.classic .list-wrap,
.f-hot .list-wrap,
.n-hot .list-wrap {
  background-color: #f5f5f5;
}
.classic-movies {
  background-color: #fff;
  padding-top: 14.5px;
}
.classic-movies a {
  text-decoration: none;
  display: block;
  color: #666;
}
.classic-movie {
  position: relative;
  margin: 0 0 20px 20px;
  display: -webkit-box;
  display: flex;
  -webkit-box-align: start;
  align-items: flex-start;
}
.classic-movie .avatar {
  display: inline-block;
}
.classic-movie .avatar img {
  width: 66px;
  height: 94px;
}
.classic-movie .movie-info {
  margin-left: 10px;
  display: inline-block;
  font-size: 13px;
  line-height: 18px;
  color: #666;
  height: 100%;
  -webkit-box-flex: 1;
  flex: 1;
  overflow: hidden;
}
.classic-movie .movie-score {
  width: 60px;
  height: 17px;
  font-size: 12px;
  color: #999;
  line-height: 17px;
  display: inline-block;
  text-align: center;
}
.classic-movie .movie-info .title {
  font-size: 17px;
  line-height: 24px;
  color: #333;
  font-weight: 700;
}
.classic-movie .movie-info > div {
  margin-bottom: 4px;
}
.line-ellipsis {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.classic-movie .movie-info {
  margin-left: 10px;
  display: inline-block;
  font-size: 13px;
  line-height: 18px;
  color: #666;
  height: 100%;
  -webkit-box-flex: 1;
  flex: 1;
  overflow: hidden;
}
.line-ellipsis {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.px-12 {
    font-size: 12px;
}
.classic-movie .movie-score .grade {
  color: #faaf00;
  font-size: 15px;
}
</style>
<script>
import Vue from 'vue'
import http from '@/Util/http'
import { Cell, List } from 'vant'
import {mapState} from 'vuex'
import moment from 'moment'
Vue.use(List).use(Cell)
Vue.filter('premiereAtfilter',(data)=>{
    return moment(data * 1000).format('YYYY-MM-DD HH:SS')
})
Vue.filter('directorfilter', (data) => {
  if (!data) {
    return '暂无主演'
  } else {
    return data
  }
})
Vue.filter('gradefilter', (data) => {
  if (!data) {
    return '暂无评'
  } else {
    return data
  }
})
export default {
     data () {
    return {
      filmitems: [],
      finished: false,
      loading: false,
      current: 1,
      total: 0,
      heighta:''
    }
  },
  methods: {
         onLoad () {
      console.log(this.total)
      if (this.filmitems.length === this.total) {
        console.log(this.filmitems)
        console.log(this.total)
        this.finished = true
        return
      }
      this.current++
      http({
        url: `/gateway?cityId=${this.Cityid}&pageNum=${this.current}&pageSize=10&type=1&k=1335803`,
        headers: {
          'X-Host': 'mall.film-ticket.film.list'
        }
      }).then(res => {
        this.filmitems = [...this.filmitems, ...res.data.data.films]
        this.total = res.data.data.total
        this.loading = false
        // console.log(res);
      })
    }
  },
    mounted () {
    this.heighta = (document.documentElement.clientHeight)-93
    console.log(this.heighta);
    http({
      url: `/gateway?cityId=${this.Cityid}&pageNum=1&pageSize=10&type=1&k=1335803`,
      headers: {
        'X-Host': 'mall.film-ticket.film.list'
      },
      method: 'get'
    }).then(res => {
      this.filmitems = res.data.data.films
      console.log(this.Cityid);
    })

  },
  computed:{
      ...mapState('City',['Cityid'])
  },
}
</script>